package com.ashin.controller;

import com.ashin.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import java.util.Map;

/**
 * @Author: Ashin
 * @Date: 2021/1/16
 * @Description: com.ashin.controller
 * @Version: 1.0.0
 */
@Controller
@RequestMapping("/modelandview_demo")
@SessionAttributes("user")
public class ModelAndViewDemoController {


    @RequestMapping("/login")
    public String login(Map map){
        System.out.println("登录成功");
        User user = new User();
        user.setName("zjh");
        user.setAge(12);
        map.put("user",user);

        return "views/login";
    }

    @RequestMapping("/login_info")
    public String loginInfo(User user){
        System.out.println(user);

        return "views/success";
    }

    private static class User{
        private String name;
        private Integer age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "User{" +
                    "name='" + name + '\'' +
                    ", age='" + age + '\'' +
                    '}';
        }
    }

}
